function hrefs2links(text) {
    // Uses Grubers regex with some extra captures
    var urire = /\b(?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|(www\d{0,3}[.]))((?:[^\s()<>]+|\([^\s()<>]+\))+(?:\([^\s()<>]+\)|[^`!()\[\]{};:'".,<>?«»“”‘’\s]))/g;

    // replace URIs with HTML anchors
    return text.replace(urire, '<a href="$&">$1$2</a>');
}

var text = hrefs2links("Check out http://example.com");

// text is 'Check out <a href="http://example.com">example.com</a>'
